<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
      <el-form-item label="计算机名" prop="skName">
        <el-input
          v-model="queryParams.skName"
          placeholder="请输入计算机名"
          clearable
          style="width: 100%"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请时间" prop="createTime">
        <el-date-picker
          v-model="applyTimeQueryTime"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          placeholder="申请时间"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 100%"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="small"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['system:user:add']"
                   type="primary"
                   plain
                   icon="el-icon-plus"
                   size="mini"
                   @click="handleAdd">新增</el-button>
      </el-col>

      <right-toolbar
        :show-search.sync="showSearch"
        :columns="columns"
        @queryTable="getList"
      />
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="severList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="计算机名"
        align="center"
        prop="skName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="ip"
        align="center"
        prop="skIp"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="申请时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="isApply" width="180">
        <template slot-scope="scope">
          <span>{{
            scope.row.isApply == "2"
              ? "驳回"
              : scope.row.isApply == "1"
              ? "同意"
              : "申请中"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['system:dict:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            >详情</el-button
          >
          <el-button
            v-hasPermi="['system:dict:remove']"
            size="mini"
            style="color: #42d885"
            type="text"
            icon="el-icon-delete"
            v-if="scope.row.isApply == '0'"
            @click="handleAgree(scope.row)"
            >同意</el-button
          >
          <el-button
            v-hasPermi="['system:dict:edit']"
            size="mini"
            type="text"
            style="color: #f56c6c"
            icon="el-icon-edit"
            v-if="scope.row.isApply == '0'"
            @click="handleReject(scope.row)"
            >驳回</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <sever-detail ref="severDetail" @ok="getList"></sever-detail>

    <el-dialog
      title="详情"
      :visible.sync="detailVisible"
      :close-on-click-modal="false"
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="form" label-width="150px" :disabled="true">
        <el-form-item label="计算机名" prop="skName">
          <el-input v-model="form.skName" />
        </el-form-item>
        <el-form-item label="ip" prop="ip">
          <el-input v-model="form.skIp" />
        </el-form-item>
        <el-form-item label="登录名" prop="skLoginName">
          <el-input v-model="form.skLoginName" />
        </el-form-item>
        <el-form-item label="申请时间" prop="createTime">
          <div class="el-datetime-width">
            <el-date-picker
              style="width: 100%"
              v-model="form.createTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </div>
        </el-form-item>
        <el-form-item label="状态" prop="isApply">
          <el-input v-model="form.isApply" />
        </el-form-item>
        <el-form-item label="备注" prop="bz">
          <el-input
            v-model="form.bz"
            type="textarea"
            :rows="2"
            autosize
          ></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import SeverDetail from "./components/detail.vue";
import {
  severApplyList,
  agreeSeverConnect,
  queryDetail,
} from "@/api/resource/sever-apply.js";
export default {
  components: { SeverDetail },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTime: void 0,
        skName: void 0,
      },
      // 表格数据
      severList: [],
      // 时间查询list
      applyTimeQueryTime: void 0,
      total: 5,
      detailVisible: false,
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      severApplyList(
        this.addDateRange(
          this.queryParams,
          this.applyTimeQueryTime,
          "CreateTime"
        )
      ).then((res) => {
        this.severList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.applyTimeQueryTime = [];
      (this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        softwareName: void 0,
        softwareCreater: void 0,
      }),
        this.handleQuery();
    },
    handleAgree(row) {
      let param = {
        skId: row.skId,
        isApply: "1",
      };
      this.$confirm("确定同意受控端连接申请吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          agreeSeverConnect(param).then((res) => {
            this.getList();
          });
        })
        .catch(() => {});
    },
    handleReject(row) {
      let param = {
        skId: row.skId,
        isApply: "2",
      };
      this.$confirm("确定驳回受控端连接申请吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          agreeSeverConnect(param).then((res) => {
            this.getList();
          });
        })
        .catch(() => {});
    },
    handleDetail(row) {
      // queryDetail({ id: row.skId }).then(res => {
      this.detailVisible = true;
      this.form = Object.assign({}, row);
      this.form.isApply =
        row.isApply == "1" ? "同意" : row.isApply == "2" ? "驳回" : "申请中";
      // })
    },
  },
};
</script>

<style></style>
